﻿using B.R.RabbitRoot.Domain.animal_husbandry;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Write.API.Applications.Commands.FarmInfoCommands;
using MediatR;

namespace B.R.RabbitRoot.Write.API.Applications.Commandhandlers.FarmInfoCommandHandler
{
    /// <summary>
    /// 企业信息
    /// </summary>
    public class FarmInfoCreamCommandHandler : IRequestHandler<FarmInfoCreamCommand, APIResult<int>>
    {
        private readonly IBaserepository<FarmInfo> _farmInfo;

        public FarmInfoCreamCommandHandler(IBaserepository<FarmInfo> farmInfo)
        {
            _farmInfo = farmInfo;
        }

        /// <summary>
        /// 企业信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<int>> Handle(FarmInfoCreamCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            var entity=await _farmInfo.AddAsync(new FarmInfo
            {
                SourceInfoId=request.SourceInfoId,
                FarmName=request.FarmName,
                ResponsiblePerson=request.ResponsiblePerson,
                LivestockCount=request.LivestockCount,
            });
            return await Task.FromResult(result.Success(entity));
        }
    }
}
